<!--
 * @Description: 
 * @Version: 1.0.0
 * @Autor: zhou
 * @Date: 2022-04-23 11:49:20
 * @LastEditors: zhou
 * @LastEditTime: 2022-08-27 11:23:13

-->
<template>
    <div class="container full-screen">
        <!-- 1左侧 -->
        <div
            v-show="!epi.open_detail"
            class="left flexcbh position-re pro-bgcolor544 p-20"
        >
            <pro-title label="核酸检测率排行[四级网格]"></pro-title>

            <div
                class="left-content fx1 flexcsh"
                v-loading="loading"
                element-loading-background="rgba(0, 0, 0, 0.3)"
            >
                <div class="search_box m-b10">
                    <el-date-picker
                        v-model="epi.table_date"
                        type="date"
                        placeholder="选择日期"
                    >
                    </el-date-picker>
                    <div class="search_btn flexrcc" @click="searchCompany">
                        <span class="txt">查 看</span>
                    </div>
                    <div class="reset_btn flexrcc" @click="searchCompany(2)">
                        <span class="txt">最近一次</span>
                    </div>
                </div>
                <div class="sort_box flexrbh m-b10">
                    <div
                        class="sort_btn fx1 flexrcc"
                        :class="epi.queryForm.sort_by ? '' : 'active'"
                        @click="searchCompany(3)"
                    >
                        <span class="txt">倒序</span>
                    </div>
                    <div
                        class="sort_btn fx1 flexrcc"
                        :class="epi.queryForm.sort_by ? 'active' : ''"
                        @click="searchCompany(4)"
                    >
                        <span class="txt">正序</span>
                    </div>
                </div>

                <div class="fx1 hidden">
                    <StaticTable
                        :columns="epi.columns1"
                        :data-list="epi.data"
                        headBg="rgba(22, 159, 196, 0.2)"
                        border_color="rgba(0, 0, 0, 0)"
                        :show_head="false"
                        rowHeight="40"
                    >
                        <template v-slot:title="scope">
                            <div class="title_box">{{ scope.row.title }}</div>
                        </template>

                        <template v-slot:col3="scope">
                            <el-progress
                                class="process_line"
                                :percentage="scope.row.col3"
                                :show-text="true"
                                :text-inside="false"
                                style="
                                    height: 100%;
                                    align-items: center;
                                    display: flex;
                                "
                                :stroke-width="9"
                            ></el-progress>
                        </template>
                    </StaticTable>
                </div>
            </div>
        </div>

        <!-- 2 中间 -->

        <!-- 3 右侧 -->
        <div
            v-show="!epi.open_detail"
            class="right flexcbh position-re pro-bgcolor544 p-20"
        >
            <pro-title label="港区网格"></pro-title>

            <div
                class="right-content fx1 flexcsh"
                v-loading="loading2"
                element-loading-background="rgba(0, 0, 0, 0.3)"
            >
                <div class="search_box m-b10">
                    <el-input
                        v-model="epi.queryForm2.gridName"
                        placeholder="请输入内容"
                    ></el-input>
                    <div class="search_btn flexrcc" @click="searchCompany2">
                        <span class="txt">搜 索</span>
                    </div>
                    <div class="reset_btn flexrcc" @click="searchCompany2(2)">
                        <span class="txt">重 置</span>
                    </div>
                </div>

                <div class="fx1 hidden">
                    <StaticTable
                        :columns="epi.columns2"
                        :data-list="epi.data2"
                        headBg="rgba(22, 159, 196, 0.2)"
                        border_color="rgba(22, 159, 196, 0.25)"
                        @onRow="onRow2"
                        headHeight="36"
                        rowHeight="40"
                    >
                    </StaticTable>
                </div>
                <!-- 分页 -->
                <ProPage
                    :pages="epi.pages2"
                    :total="epi.total2"
                    ref="ref_page2"
                    @on_page="changePage($event, 28)"
                ></ProPage>
            </div>
        </div>

        <!-- 4弹窗列表 -->
        <div class="dialog_box flexrcc" v-if="epi.open_detail">
            <ListDetail
                :title="epi.detail_title"
                @close_info="onCloseInfo"
            >
                <div class="full-screen hidden">
                    <div class="p-row30">
                        <EpiContentNav
                            :list="epi.detail_btn"
                            @change="changeContent"
                        ></EpiContentNav>
                    </div>

                    <div
                        v-if="epi.cut_content == 1"
                        class="dialog_content1 flexcsc"
                    >
                        <div class="item top m-b20">
                            <div class="flex m-b10">
                                <div class="label">上级网格:</div>
                                <div class="value">{{ "南康镇" }}</div>
                            </div>
                            <div class="flex">
                                <div class="label">下级网格:</div>
                                <div class="value fx1 grid-gap20">
                                    <span>第一片区</span>
                                    <span>第二片区</span>
                                    <span>第三片区</span>
                                    <span>第四片区</span>
                                    <span>第五片区</span>
                                    <span>第六片区</span>
                                    <span>第七片区</span>
                                    <span>第八片区</span>
                                    <span>第九片区</span>
                                </div>
                            </div>
                        </div>
                        <div class="item bottom">
                            <div class="flex m-b10">
                                <div class="label">网格长:</div>
                                <div class="value">{{ "黄大强" }}</div>
                            </div>
                            <div class="flex">
                                <div class="label">网格员:</div>
                                <div class="value grid-gap20">
                                    <span>刘小军</span>
                                    <span>张xx</span>
                                    <span>李四</span>
                                    <span>张三</span>
                                    <span>王大海</span>
                                    <span>李国富</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div
                        v-else-if="epi.cut_content == 2"
                        class="full-screen flexcb"
                    >
                        <div class="fx1 hidden">
                            <StaticTable
                                :columns="list_columns"
                                :data-list="list_info"
                                headBg="rgba(22, 159, 196, 0.2)"
                                border_color="rgba(22, 159, 196, 0.25)"
                                headHeight="36"
                                @onClick="onClickDetail"
                            >
                                <template v-slot:col4="{ row }">
                                    <div class="w-text">
                                        {{ getType(row.col4) }}
                                    </div>
                                </template>
                                <template v-slot:col6="{ row }">
                                    <div class="w-text">
                                        {{ getResult(row.col6) }}
                                    </div>
                                </template>
                            </StaticTable>
                        </div>
                        <!-- 分页 -->
                        <ProPage
                            :pages="epi.pages"
                            ref="ref_special"
                            @on_page="changePage($event, 28)"
                        ></ProPage>
                    </div>
                </div>
            </ListDetail>
        </div>
    </div>
</template>

<script>
import ProTitle from "@/components/Pro/ProTitle";
import ProTitle2 from "@/components/Pro/ProTitle2";
import StaticTable from "@/components/Common/StaticTable.vue";
import ProShade from "./ProShade";
import PieChart from "@/components/Chart/PieChart/PieChart.vue";
import LineChart from "@/components/Chart/LineChart/LineChart.vue";
import BarChart from "@/components/Chart/BarChart/BarChart.vue";
import ListDetail from "./ListDetail";
import DynamicTable from "@/components/Common/DynamicTable.vue";
import ProPage from "./ProPage";
import EpiContentNav from "./EpiContentNav";
import { listEmphasisCompany } from "@/api/epiview.js";

import { my_option } from "@/utils/mock/proview/company";

import {
    getCompany,
    listCompanyWork,
    listWork,
    detailWork,
} from "@/api/proview.js";

export default {
    name: "NavCompany",
    components: {
        ProTitle,
        ProTitle2,
        DynamicTable,
        StaticTable,
        ProShade,
        PieChart,
        LineChart,
        BarChart,
        ListDetail,
        ProPage,
        EpiContentNav,
    },
    props: {
        company_type: {
            type: Array,
            default: () => [],
        },
    },
    data() {
        return {
            loading: false,
            loading2: false,
            compnyType: false,
            //信息-------------------------------
            epi: {
                data: [],
                columns1: my_option.columns1,
                cut_companyid: "",
                queryForm: {
                    sort_by: false, // asc (true) 正序  desc(false) 倒序
                    gridName: "",
                },

                data2: [],
                columns2: my_option.columns2,
                queryForm2: {
                    current: 1,
                    size: 10,
                    level: 0,
                    gridName: "",
                    sortList: [
                        {
                            asc: false,
                            column: "",
                        },
                    ],
                },
                total2: 3,
                pages2: 1,

                // 详情-----
                cut_content: 1,
                detail_btn: [
                    { label: "企业信息", id: 1 },
                    { label: "员工信息", id: 2 },
                    { label: "检测信息", id: 3 },
                    { label: "对比名单", id: 4 },
                ],
                queryForm3: {
                    company_id: "",
                    pageSize: 13,
                    pageNum: 1,
                },
                table_date: null,
                open_detail: false,
                detail_title: "企业信息",
                pages: 1,
            },
            // 地图点的集合
            MarkerData: [],

            // 弹出层--------------------------
            list_columns: my_option.list_columns,
            list_info: [],
            open_detail2: false,
            detail2_title: "作业明细",
            detail2_info: {},
        };
    },
    computed: {
        // 0 计算是否 跨列
        getAcrossCol() {
            return (p) => {
                if (p == 3) return "across-col3";
                else if (p == 2) return "across-col2";
                else return "";
            };
        },

        // 作业类型
        getType() {
            return (p) => {
                if (p == 1) return "吊装作业";
                else if (p == 2) return "动火作业";
                else if (p == 3) return "动土作业";
                else if (p == 4) return "断路工作";
                else if (p == 5) return "高处作业";
                else if (p == 6) return "设备检维修作业";
                else if (p == 7) return "盲板抽堵作业";
                else if (p == 8) return "受限空间作业";
                else {
                    return "-";
                }
            };
        },
        // 处理结果
        getResult() {
            return (p) => {
                if (p == 1) return "进行中";
                else if (p == 2) return "成功";
                else if (p == 3) return "失败";
                else {
                    return "-";
                }
            };
        },
    },

    watch: {},

    created() {
        // this.getData();
        this.getData2();
    },
    mounted() {},
    methods: {
        /** 关闭地图的消息弹窗(给父组件调用) */
        closeMap(id) {
            this.MarkerData.forEach((item) => {
                if (id == this.epi.cut_companyid) {
                    // 点击x号 关闭 当前消息窗口
                    item.grade = 28;
                } else {
                    // 点击另外的地图标点, 关闭旧窗口, 打开新窗口时, 保留新窗口的icon高亮
                    if (item.id != this.epi.cut_companyid) {
                        item.grade = 28;
                    }
                }
            });
        },
        /** 点击地图弹窗详情(给父组件调用) */
        detailMap(id) {
            this.epi.open_detail = true;
            // this.epi.cut_companyid = id;
        },
        /** 点击表格的某行 */
        onRow2(row) {
            this.epi.open_detail = true;
        },
        /** 点击企业列表 的某列 */
        onClick(row, col) {
            // if (col.prop == "title") {
            //     this.epi.open_detail = true;
            //     this.epi.detail_title = row.title;
            //     // this.getCompany(row.id);
            //     this.epi.cut_companyid = row.id;
            //     this.epi.open_detail = true;
            // } else if (col.prop == "col3") {
            //     this.getIntroduction(row.id, true);
            // } else if (col.prop == "col4") {
            //     this.epi.open_detail = false;
            //     this.detail_title = row.title;
            //     this.epi.queryForm2.company_id = row.id;
            //     this.epi.queryForm2.pageNum = 1;
            //     if (this.$refs["ref_special"])
            //         this.$refs["ref_special"].resetPage();
            //     this.listWork();
            // }
            // this.$emit("onClick", row, col);
        },
        //
        onClickDetail(row, col) {
            this.detail2_title = row.col3;
            if (col.prop == "col7") {
                this.open_detail2 = true;
                this.detailWork(row.id);
            }
        },
        /** 关闭列表明细 */
        onCloseInfo() {
            this.epi.open_detail = false;
        },
        /** 关闭详情 */
        onCloseDetail() {
            this.open_detail2 = false;
        },
        /** 重置弹窗数据 */
        reset() {
            this.epi.open_detail = false;
            this.$refs["ref_detail"].reset();
        },
        /** 分页切换 */
        changePage(num, type) {
            if (type == 28) {
                this.epi.queryForm2.current = num;
                this.listData2();
            }
        },

        /** 搜索 */
        searchCompany(type = 1) {
            // this.epi.queryForm2.pageNum = 1;
            // if(this.$refs['ref_special']) this.$refs['ref_special'].resetPage()
            if (type == 2) {
                this.epi.queryForm.date = "";
                this.epi.table_date = null;
            } else if (type == 3) {
                this.epi.queryForm.sort_by = false;
            } else if (type == 4) {
                this.epi.queryForm.sort_by = true;
            }
            this.getData();
        },
        /** 搜索 */
        searchCompany2(type = 1) {
            this.epi.queryForm2.pageNum = 1;
            if(this.$refs['ref_page2']) this.$refs['ref_page2'].resetPage()
            if (type == 2) {
                this.epi.queryForm2.gridName = '';
            }
            this.getData2();
        },

        /** 弹窗列表数据 */
        listWork() {
            listWork(this.epi.queryForm2).then((res) => {
                if (res.code == 0) {
                    this.epi.pages = res.data.pages;
                    this.list_info = res.data.data.map((item) => {
                        return {
                            id: item.id,
                            title: item.work_start_time,
                            col2: item.work_end_time,
                            col3: item.work_name,
                            col4: item.type,
                            col5: item.header,
                            col6: item.result,
                            col7: "详情",
                        };
                    });
                }
            });
        },
        /** 弹窗详情数据 */
        detailWork(id) {
            detailWork({ work_id: id }).then((res) => {
                if (res.code == 0) {
                    let data = res.data;
                    let temp = {
                        left: [
                            {
                                label: "特殊作业名称",
                                value: data.work_name,
                            },
                            {
                                label: "类型",
                                value: data.type,
                                is_type: false,
                            },
                            {
                                label: "操作人",
                                value: data.work_user_name,
                                is_list: false,
                            },
                            {
                                label: "操作时间",
                                value: data.work_start_time,
                            },
                            {
                                label: "现场负责人",
                                value: data.header,
                            },
                            {
                                label: "操作方案",
                                value: data.work_norms,
                            },
                            {
                                label: "作业结果",
                                value: data.result,
                                is_result: false,
                            },
                            {
                                label: "操作过程",
                                value: data.process,
                                is_card: true,
                            },
                        ],
                    };
                    this.detail2_info = temp;
                }
            });
        },
        /** 弹窗内容切换 */
        changeContent(id) {
            this.epi.cut_content = id;
        },

        /** 左侧列表数据 */
        getData() {
            if (this.epi.table_date) {
                this.epi.queryForm.date = this.parseTime(
                    this.epi.table_date,
                    "{y}-{m}-{d}"
                );
            } else {
                this.epi.queryForm.date = "";
            }

            this.loading = true;
            let temp = {
                sort_by: this.epi.queryForm.sort_by ? "asc" : "desc",
                gridName: this.epi.queryForm.gridName,
                date: this.epi.queryForm.date,
            };
            listCompanyWork(temp).then((res) => {
                if (res.code == 0) {
                    this.epi.data = res.data.company_list.map(
                        (item, index) => {
                            return {
                                id: item.id,
                                title: index + 1,
                                col2: "xxxxxw网络",
                                col3: 90,
                            };
                        }
                    );
                    this.MarkerData = res.data.company_list.map((item) => {
                        return {
                            id: item.id,
                            lng: item.lng,
                            lat: item.lat,
                            content: {
                                name: item.gridName,
                            },
                            introduction: null,
                            grade: 28,
                        };
                    });
                    this.$emit("marker", this.MarkerData);
                } else {
                    this.epi.data = [];
                }
                this.loading = false;
            });
        },
        /** 右侧列表数据 */
        getData2() {
            this.loading2 = true;
            let temp = {
                current: this.epi.queryForm2.current,
                size: this.epi.queryForm2.size,
                level: this.epi.queryForm2.level,
                gridName: this.epi.queryForm2.gridName,
            };
            listEmphasisCompany(temp).then((res) => {
                if (res.code == 0) {
                    this.epi.data2 = res.data.records.map(
                        (item, index) => {
                            return {
                                id: item.id,
                                title: index + 1,
                                col2: item.gridName,
                                col3: item.type || '-',
                                col4: item.count || '-'
                            };
                        }
                    );
                } else {
                    this.epi.data2 = [];
                }
                this.loading2 = false;
            });
        },
        /** 点击地图标点emit=false  点击table弹出简介信息时emit=true */
        getIntroduction(id, emit = false) {
            this.epi.cut_companyid = id;
            getCompany(id).then((res) => {
                if (res.code == 0) {
                    let data = res.data;
                    this.epi.detail_title = data.company_name;

                    let temp = [
                        {
                            label: "名称",
                            value: data.company_name,
                        },
                        {
                            label: "行业类型",
                            value: "-",
                            is_industry: true,
                        },
                        {
                            label: "法定代表人",
                            value: data.legal_name,
                        },
                        {
                            label: "法人电话",
                            value: data.legal_phone,
                            is_tel: false,
                        },
                        {
                            label: "查看详情",
                            value: "",
                            is_detail: true,
                            is_video: false,
                        },
                    ];

                    this.MarkerData.forEach((item) => {
                        if (item.id == id) {
                            item.introduction = temp;
                            item.grade = 31;
                            if (emit) {
                                this.$emit("onClick", item); // 点击table某列 响应的事件
                            } else {
                                this.$emit("changeFlag", item); // 点击地图icon 响应的事件
                            }
                        } else {
                            item.grade = 28;
                        }
                    });
                }
            });
        },
    },
};
</script>

<style lang="scss">
.el-image-viewer__wrapper {
    top: vh(100);
    bottom: vh(100);
    left: vh(200);
    right: vh(200);
}

.el-loading-spinner .circular .path {
    stroke: #2ef7fc !important;
}

.el-progress__text {
    color: #fff;
}
.el-progress-bar__inner {
    border-radius: vw(1);
    background: linear-gradient(90deg, #0f699c 0%, #49d4ff 100%);
}
</style>

<style lang="scss" scoped>
.container {
    ::v-deep .el-input__inner {
        color: white;
    }
    ::v-deep .el-input--medium .el-input__inner {
        background-color: #002440;
        border: 1px solid #094666;
    }
    .process_line {
        width: vw(200);
        ::v-deep .el-progress-bar__outer {
            border-radius: 0;
            background-color: rgba(255, 255, 255, 0.1);
        }
    }

    .left {
        position: absolute;
        z-index: 12;
        left: vw(30);
        top: vh(88);
        bottom: vh(40);
        width: vw(484);

        .search_box {
            display: grid;
            grid-template-columns: 5fr 2fr 2fr;
            grid-gap: vh(20) vw(20);
            .search_btn {
                cursor: pointer;
                padding: 0px 10px;
                height: 36px;
                background: linear-gradient(180deg, #033748 0%, #169fc4 100%);
                border: 1px solid rgba(41, 173, 249, 0.4);
                .txt {
                    font-size: 14px;
                    color: white;
                }
            }
            .reset_btn {
                cursor: pointer;
                padding: 0px 10px;
                height: 36px;
                background: #002440; // 16171F
                border: 1px solid rgba(41, 173, 249, 0.4);
                .txt {
                    font-size: 14px;
                    color: white;
                }
            }
        }
        .sort_box {
            .sort_btn {
                cursor: pointer;
                padding: 0px 10px;
                height: vh(32);
                background: #002440; // 16171F
                border: 1px solid rgba(22, 159, 196, 0.25);
                .txt {
                    font-size: 14px;
                    color: white;
                }
                &.active {
                    background: rgba(22, 159, 196, 0.2);
                    .txt {
                        color: #61ffff;
                    }
                }
            }
        }
        .title_box {
            padding: 0 vw(10);
            background: rgba(22, 159, 196, 0.2);
            border: 1px solid rgba(45, 205, 255, 0.24);
            border-radius: 2px;
            color: #2dcdff;
        }
    }

    .right {
        position: absolute;
        z-index: 12;
        right: vw(30);
        top: vh(88);
        bottom: vh(40);
        width: vw(484);
        .right-content {
            .search_box {
                display: grid;
                grid-template-columns: 5fr 2fr 2fr;
                grid-gap: vh(20) vw(20);
                .search_btn {
                    cursor: pointer;
                    padding: 0px 10px;
                    height: 36px;
                    background: linear-gradient(
                        180deg,
                        #033748 0%,
                        #169fc4 100%
                    );
                    border: 1px solid rgba(41, 173, 249, 0.4);
                    .txt {
                        font-size: 14px;
                        color: white;
                    }
                }
                .reset_btn {
                    cursor: pointer;
                    padding: 0px 10px;
                    height: 36px;
                    background: #002440; // 16171F
                    border: 1px solid rgba(41, 173, 249, 0.4);
                    .txt {
                        font-size: 14px;
                        color: white;
                    }
                }
            }
        }
    }

    .iconfont {
        margin-right: vw(5);
    }

    // 弹出层
    .dialog_box {
        position: absolute;
        z-index: 15;
        left: 0;
        top: vh(56);
        height: calc(100% - vh(56));
        width: 100%;
        background: rgba(0, 6, 17, 0.5);
        backdrop-filter: blur(20px);

        .dialog_content1 {
            .item {
                width: vw(480);
                background: rgba(22, 159, 196, 0.2);
                border: 1px solid rgba(22, 159, 196, 0.25);
                padding: vh(24) vw(20);

                .label {
                    color: #fff;
                    margin-right: vw(10);
                }
                .value {
                    color: #2ef7fc;
                }
            }
        }
    }
}
</style>
